#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > r12_prop_n2.info <<'%EOF%'
   r12_prop_n2
   ----------
   Molecule:         N2
   Wave Function:    MP2-R12 / AhlrichsVTZ AhlrichsVTZ
   Test Purpose:     Check R12 second moment of charge 
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > r12_prop_n2.mol <<'%EOF%'
BASIS
Ahlrichs-VTZ Ahlrichs-VTZ
MP2-R12 first order property calculation on N2
small basis
    2    3  X  Y  Z   1.00D-15
 1      7.    1
N     0.0000000000000000  0.0000000000000000 1.03715750000000000       *
 2      7.    1
N     0.0000000000000000  0.0000000000000000 1.03715750000000000       *
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > r12_prop_n2.dal <<'%EOF%'
**DALTON
.RUN WAVE FUNCTION
**INTEGRAL
.THETA
.SECMOM
**WAVE FUNCTION
.CC
*SCF INP
.THRESH
 1.0D-10
*CC INP
.MP2
.PRINT
 3 
.THRENR
1.0D-10
.FROIMP
1 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0
.THRLEQ
1.0D-07
*CCFOP
.QUADRU
.SECMOM
*R12
.NO 2
.R12XXL
.R12PRP
.NO RXR
*ORBITALS
.MOSTART
 H1DIAG
**END OF DALTON INPUT
%EOF%

#######################################################################



#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >r12_prop_n2.check
cat >>r12_prop_n2.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# ?
CRIT1=`$GREP "Alfa\*\*2 Invariant\: * 167\.761121" $log | wc -l`
CRIT2=`$GREP "Beta\*\*2 Invariant\: * 288\.216300" $log | wc -l`
TEST[1]=`expr   $CRIT1 \+ $CRIT2`
CTRL[1]=2
ERROR[1]="Alfa Beta 1 NOT CORRECT"

# ?
CRIT1=`$GREP "Isotropic Property\: * 12\.952263 a\.u\." $log | wc -l`
CRIT2=`$GREP "Property anisotropy invariant\: * 16\.976934 a\.u\." $log | wc -l`
TEST[2]=`expr   $CRIT1 \+ $CRIT2`
CTRL[2]=2
ERROR[2]="Property 1 NOT CORRECT"

# ?
CRIT1=`$GREP "Alfa\*\*2 Invariant\: * 167\.828228" $log | wc -l`
CRIT2=`$GREP "Beta\*\*2 Invariant\: * 288\.649611" $log | wc -l`
TEST[3]=`expr   $CRIT1 \+ $CRIT2`
CTRL[3]=2
ERROR[3]="Alfa Beta 2 NOT CORRECT"

# ?
CRIT1=`$GREP "Isotropic Property\: * 12\.954853 a\.u\." $log | wc -l`
CRIT2=`$GREP "Property anisotropy invariant\: * 16\.989691 a\.u\." $log | wc -l`
TEST[4]=`expr   $CRIT1 \+ $CRIT2`
CTRL[4]=2
ERROR[4]="Property 2 NOT CORRECT"

# ?
CRIT1=`$GREP "Alfa\*\*2 Invariant\: * 17(0| )\.503249" $log | wc -l`
CRIT2=`$GREP "Beta\*\*2 Invariant\: * 289\.771830" $log | wc -l`
TEST[5]=`expr   $CRIT1 \+ $CRIT2`
CTRL[5]=2
ERROR[5]="Alfa Beta 3 NOT CORRECT"

# ?
CRIT1=`$GREP "Isotropic Property\: * 13\.057689 a\.u\." $log | wc -l`
CRIT2=`$GREP "Property anisotropy invariant\: * 17\.022686 a\.u\." $log | wc -l`
TEST[6]=`expr   $CRIT1 \+ $CRIT2`
CTRL[6]=2
ERROR[6]="Property 3 NOT CORRECT"


PASSED=1
for i in 1 2 3 4 5 6
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi

%EOF%
#######################################################################

